package view.player;

import java.awt.Dimension;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;

import constants.Icons;
import controller.CompleteListener;


import view.BaseComponent;


public class GrenadeCountPanel extends BaseComponent {

	private int count;
	private String type;
	
	private JLabel textLabel;
	private JButton add;
	private JButton del;
	
	public GrenadeCountPanel(String type_) {
		count = 0;
		type = type_;
		
		textLabel = new JLabel(count+" "+type);
		add = new JButton(Icons.getIcon("add"));
		del = new JButton(Icons.getIcon("del"));
		
		add.setActionCommand("add"+type); // Type should be "FB", "HE", or "SG".
		del.setActionCommand("del"+type);
		
		add.setPreferredSize(new Dimension(add.getIcon().getIconWidth(),
				add.getIcon().getIconHeight()));
		add.setMaximumSize(new Dimension(add.getIcon().getIconWidth(),
				add.getIcon().getIconHeight()));
		del.setPreferredSize(new Dimension(del.getIcon().getIconWidth(),
				del.getIcon().getIconHeight()));
		del.setMaximumSize(new Dimension(del.getIcon().getIconWidth(),
				del.getIcon().getIconHeight()));
		
		this.setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
		this.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
		
		this.add(textLabel);
		this.add(Box.createHorizontalStrut(5));
		this.add(add);
		this.add(Box.createHorizontalStrut(5));
		this.add(del);
		
		this.setMaximumSize(new Dimension(80,25));
		this.setPreferredSize(new Dimension(80,25));
	}

	public int getCount() {
		return count;
	}
	
	public void setCount(int newCount) {
		count = newCount;
		textLabel.setText(count+" "+type);
	}
	
	public void incCount() {
		count++;
		textLabel.setText(count+" "+type);
	}
	
	public void decCount() {
		count--;
		textLabel.setText(count+" "+type);
	}
	
	@Override
	public void attachListener(CompleteListener l) {
		// TODO Auto-generated method stub
		add.addActionListener(l);
		del.addActionListener(l);
	}

	@Override
	public void setEnabled(boolean enable) {
		// TODO Auto-generated method stub
		add.setEnabled(enable);
		del.setEnabled(enable);
	}

	public JButton getAdd() {
		return add;
	}

	public JButton getDel() {
		return del;
	}
}
